<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>

<body>
	<form id="form1" method="post">
        <div style="padding-left:30px;padding-bottom:10px;">
            <table style="table-layout:fixed;" cellspacing="0" cellpadding="5">
            	<tr>
            		<td colspan="4">
            			<span style="display: inline-block;width: 73px">名称：</span><input name="name" class="mini-textbox" required="true" vtype="maxLength:50" style="width: 260px" />
                    </td>
            	</tr>
            	<tr>
            		<td colspan="4">
            			<span style="display: inline-block;width: 70px">地址：</span>
		        		<input name="provinceId" id="province_val" class="mini-hidden"/>
		        		<input id="province" class="mini-textbox" onfocus="focusP" emptyText="请选择省份"/>
		        		<input name="cityId" class="mini-hidden" id="city_val" />
		        		<input class="mini-textbox" id="city" readonly="true" emptyText="请选择城市"/>
		        		<input name="districtId" id="district_val" class="mini-hidden"/>
		        		<input class="mini-textbox" id="district" readonly="true" emptyText="请选择区县"/>
		        	</td>
                </tr>
                <tr>
                    <td colspan="4">    
                        <input name="address" id="mini-address" class="mini-textbox" readonly="true" required="true" vtype="maxLength:50" style="margin-left:75px;width: 382px" />
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                    	<span style="display: inline-block;width: 70px">电子邮件：</span>
                    	<input name="email" class="mini-textbox" vtype="email" style="width: 150px;"/>
                    	传真：<input name="fax" class="mini-textbox" vtype="rangeLength:11,12;int" style="width: 150px;"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                    	<span style="display: inline-block;width: 73px">联系人：</span><input name="linkMan" class="mini-textbox" required="true" vtype="maxLength:15" style="width: 150px"/>
                    	电话：<input name="phoneNum" class="mini-textbox" vtype="rangeLength:11,12;int" style="width: 150px"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                    	<span style="display: inline-block;width: 70px">邮编：</span>
                    	<input name="postCode" class="mini-textbox" vtype="int;rangeLength:6,6" style="width: 150px"/>
                    	网址：<input name="url" class="mini-textbox" vtype="url" style="width: 150px"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                    	<span style="display: inline-block;width: 70px">备注：</span>
                        <input name="description" class="mini-textarea" vtype="maxLength:255" style="width:382px;" />
                    </td>
                </tr>
            </table>
            <input id="text1"  name="id" class="mini-hidden" />
        </div>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>
    <div id="win1" class="mini-window" allowDrag="false" showHeader="false" title="选择地址—省份" style="width: 300px;height: 150px;">
	</div>
	<div id="win2" class="mini-window" allowDrag="false" showHeader="false" title="选择地址—省份" style="width: 300px;height: 150px;">
	</div>
	<div id="win3" class="mini-window" allowDrag="false" showHeader="false" title="选择地址—省份" style="width: 300px;height: 150px;">
	</div>
</body>

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	
	function SaveData() {
        var o = form.getData(true);            
		
        form.validate();
        if (form.isValid() == false) return;
        $.ajax({
            url: "media_edit_save.do",
			type: 'post',
			dataType: 'json',
            data: o,
            cache: false,
            success: function (text) {
            	if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else {
	            	mini.alert("数据错误");
	            }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
            }
        });
    }
	
	function onOk(e) {
        SaveData();
    }
	
	function SetData(data){
	     data = mini.clone(data);
	     form.setData(data.row);
	}
	
	function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
	
	function onCancel(e) {
        CloseWindow("cancel");
    }

	// 弹出省份列表
 	var win1 = mini.get("win1");
 	var province = mini.get("province");
 	var provinceVal = mini.get("province_val");
 	function focusP(e) {
 		var el=e.sender.getEl();
		var bodyEl1 = win1.getBodyEl();
		$(bodyEl1).empty();
		$.post("medical_media_find_province.do", {}, function(data) {
			win1.showAtEl(el, {
			   xAlign:"left",
			   yAlign:"below"
			});
			$.each(data, function(i, obj) {
				$(bodyEl1).append("</li><a href='javascript:loadC("+obj.id+", "+'"'+obj.pName+'"'+")' style='padding: 5px;'>"+obj.pName+"</a>");
			});
		}, "json");
		
 	}
 
 	// 通过省加载城市
 	var city = mini.get("city");
 	var cityVal = mini.get("city_val");
 	var win2 = mini.get("win2");
 	function loadC(p_id, p_name) {
 		var el = city.getEl();
		var bodyEl2 = win2.getBodyEl();
		$(bodyEl2).empty();
		$.post("medical_media_find_city.do", {provinceId: p_id}, function(data) {
	 		provinceVal.setValue(p_id);
	 		province.setValue(p_name);
	 		win1.hide();
			win2.showAtEl(el, {
			   xAlign:"left",
			   yAlign:"below"
			});
			$.each(data, function(i, obj) {
				$(bodyEl2).append("<a href='javascript:loadD("+obj.id+", "+'"'+obj.cName+'"'+")' style='padding: 5px;'>"+obj.cName+"</a>");
				mini.parse();
			});
		}, "json");
 	}
 	
 	// 通过城市加载区县
 	var win3 = mini.get("win3");
 	var district = mini.get("district");
 	var districtVal = mini.get("district_val");
 	function loadD(c_id, c_name) {
 		var el = district.getEl();
 		var bodyEl3 = win3.getBodyEl();
 		$(bodyEl3).empty();
 		$.post("medical_media_find_district.do", {cityId: c_id}, function(data) {
 			city.setValue(c_name);
 			cityVal.setValue(c_id);
 			win2.hide();
 			win3.showAtEl(el, {
 			   xAlign:"left",
 			   yAlign:"below"
 			});
 			$.each(data, function(i, obj) {
				$(bodyEl3).append("<a href='javascript:setD("+obj.id+", "+'"'+obj.dName+'"'+")' style='padding: 5px;'>"+obj.dName+"</a>");
				mini.parse();
			});
 		}, "json");
 	}
 	
 	// 设置区县
 	function setD(d_id, d_name) {
 		win3.hide();
 		districtVal.setValue(d_id);
 		district.setValue(d_name);
 		address();
 	}
 	
 	// 设置地区值
 	function address(){
 		var address = mini.get("mini-address");
 		address.setValue(province.getValue()+'-'+city.getValue()+'-'+district.getValue());
 	}
</script>